package com.seguridad.txwrapping;

import org.apache.log4j.Logger;

import com.seguridad.txwrapping.tester.WSSWTester;

public class Main {

	static Logger logger = Logger.getLogger(Main.class);

	public static void main(String[] args) {
		
		if (args.length < 4){
			showUsage();
			System.exit(0);
		}
		
		WSSWTester wsswTester = null;
		try{
			TestType testType = TestType.valueOf(args[0].toUpperCase());
			String url = args[1];
			String validMessagePath = args[2];
			String elementName = args[3];
			String elementToDuplicate = null;
			if(args.length >= 5){
				elementToDuplicate = args[4];
			}
			
			wsswTester = WSSWrapperTesterBuilder.build(testType,
														url,
														validMessagePath,
														elementName,
														elementToDuplicate);
			TestResult result = wsswTester.test();
			System.out.println();
			System.out.println(result.getStatus() + " - " + result.getMessage());
			
		} catch (Exception e) {
			logger.info("ERROR");
			logger.debug(e.getMessage());
			showUsage();
			System.exit(0);
		}
	}
	
	public static void showUsage(){
		System.out.println("");
		System.out.println("CORRECT USAGE");
		System.out.println("--- SIMPLE ANCESTRY CONTEXT ---");
		System.out.println("java -jar textXMLWrapping.jar SIMPLE urlEndpoint validMsgPath IdToWrap");
		System.out.println("--- OPTIONAL CONTEXT ---");
		System.out.println("java -jar textXMLWrapping.jar OPTIONAL urlEndpoint validMsgPath IdToWrap");	
		System.out.println("--- SIBLING CONTEXT ---");
		System.out.println("java -jar textXMLWrapping.jar SIBLING urlEndpoint validMsgPath IdToWrap elementTagToDuplicate");
		System.out.println("");
	}

}
